From 0c5c054ccbe9c1ba9a392f2705669c91c0bd11fd Mon Sep 17 00:00:00 2001 From: parkrrrr Date: Fri, 25 Jul 2003 16:09:43 +0000 Subject: [PATCH] add argument type and flags to argument specifications as an aid to potential GUIs --- gpsbabel/arcdist.c | 10 +++++---- gpsbabel/cetus.c | 4 ++-- gpsbabel/defs.h | 13 +++++++++++ gpsbabel/duplicate.c | 8 ++++--- gpsbabel/easygps.c | 4 ++-- gpsbabel/filter_vecs.c | 5 +++-- gpsbabel/gpilots.c | 4 ++-- gpsbabel/gpspilot.c | 4 ++-- gpsbabel/gpx.c | 51 +++++++++++++++++++++++++++++++++--------- gpsbabel/magproto.c | 9 ++++---- gpsbabel/mapsource.c | 4 ++-- gpsbabel/pcx.c | 4 ++-- gpsbabel/polygon.c | 8 ++++--- gpsbabel/position.c | 19 ++++++++++------ gpsbabel/quovadis.c | 4 ++-- gpsbabel/tiger.c | 14 +++++++----- gpsbabel/vecs.c | 5 +++-- gpsbabel/xcsv.c | 23 ++++++++++++------- 18 files changed, 130 insertions(+), 63 deletions(-) diff --git a/gpsbabel/arcdist.c b/gpsbabel/arcdist.c index bd0c7dd6c..6bf769447 100644 --- a/gpsbabel/arcdist.c +++ b/gpsbabel/arcdist.c @@ -41,10 +41,12 @@ typedef struct { static arglist_t arcdist_args[] = { - {"file", &arcfileopt, "File containing vertices of arc"}, - {"distance", &distopt, "Maximum distance from arc"}, - {"exclude", &exclopt, "Exclude points close to the arc"}, - {0, 0, 0} + {"file", &arcfileopt, "File containing vertices of arc", + ARGTYPE_FILE | ARGTYPE_REQUIRED}, + {"distance", &distopt, "Maximum distance from arc", + ARGTYPE_FLOAT | ARGTYPE_REQUIRED}, + {"exclude", &exclopt, "Exclude points close to the arc", ARGTYPE_BOOL}, + {0, 0, 0, 0} }; static double gcdist( double lat1, double lon1, double lat2, double lon2 ) { diff --git a/gpsbabel/cetus.c b/gpsbabel/cetus.c index 713307e63..bceb5099e 100644 --- a/gpsbabel/cetus.c +++ b/gpsbabel/cetus.c @@ -82,8 +82,8 @@ static char *dbname = NULL; static arglist_t cetus_args[] = { - {"dbname", &dbname, "Database name"}, - {0, 0, 0} + {"dbname", &dbname, "Database name", ARGTYPE_STRING }, + {0, 0, 0, 0 } }; static void diff --git a/gpsbabel/defs.h b/gpsbabel/defs.h index 22c9552ef..273183b3f 100644 --- a/gpsbabel/defs.h +++ b/gpsbabel/defs.h @@ -235,10 +235,23 @@ void setshort_mustupper(void *, int n); void setshort_mustuniq(void *, int n); void setshort_whitespace_ok(void *, int n); +#define ARGTYPE_UNKNOWN 0 +#define ARGTYPE_INT 0x00000001 +#define ARGTYPE_FLOAT 0x00000002 +#define ARGTYPE_STRING 0x00000003 +#define ARGTYPE_BOOL 0x00000004 +#define ARGTYPE_FILE 0x00000005 +#define ARGTYPE_OUTFILE 0x00000006 +#define ARGTYPE_REQUIRED 0x40000000 + +#define ARGTYPE_TYPEMASK 0x00000fff +#define ARGTYPE_FLAGMASK 0xfffff000 + typedef struct arglist { char *argstring; char **argval; char *helpstring; + long argtype; } arglist_t; typedef struct ff_vecs { diff --git a/gpsbabel/duplicate.c b/gpsbabel/duplicate.c index cd5cc5dd3..570cf3701 100644 --- a/gpsbabel/duplicate.c +++ b/gpsbabel/duplicate.c @@ -28,9 +28,11 @@ static char *lcopt = NULL; static arglist_t dup_args[] = { - {"shortname", &snopt, "Suppress duplicate waypoints based on name"}, - {"location", &lcopt, "Suppress duplicate waypoint based on coords"}, - {0, 0, 0} + {"shortname", &snopt, "Suppress duplicate waypoints based on name", + ARGTYPE_BOOL}, + {"location", &lcopt, "Suppress duplicate waypoint based on coords", + ARGTYPE_BOOL}, + {0, 0, 0, 0} }; diff --git a/gpsbabel/easygps.c b/gpsbabel/easygps.c index efc67172e..7ec472e4f 100644 --- a/gpsbabel/easygps.c +++ b/gpsbabel/easygps.c @@ -31,8 +31,8 @@ static char *deficon = "Waypoint"; static arglist_t easygps_args[] = { -/* {"deficon", &deficon, "Default icon name"}, */ - {0, 0, 0} +/* {"deficon", &deficon, "Default icon name", ARGTYPE_STRING}, */ + {0, 0, 0, 0 } }; static void diff --git a/gpsbabel/filter_vecs.c b/gpsbabel/filter_vecs.c index 791a77cf3..c8b84afd3 100644 --- a/gpsbabel/filter_vecs.c +++ b/gpsbabel/filter_vecs.c @@ -127,8 +127,9 @@ disp_filter_vecs(void) printf(" %-20.20s %-50.50s\n", vec->name, vec->desc); for (ap = vec->vec->args; ap && ap->argstring; ap++) { - printf(" %-18.18s %-.50s\n", - ap->argstring, ap->helpstring); + printf(" %-18.18s %-.50s %s\n", + ap->argstring, ap->helpstring, + (ap->argtype&ARGTYPE_REQUIRED)?"(required)":""); } } } diff --git a/gpsbabel/gpilots.c b/gpsbabel/gpilots.c index 2bda982da..9759ecf9c 100644 --- a/gpsbabel/gpilots.c +++ b/gpsbabel/gpilots.c @@ -117,8 +117,8 @@ static char *dbname = NULL; static arglist_t my_args[] = { - {"dbname", &dbname, "Database name"}, - {0, 0, 0} + {"dbname", &dbname, "Database name", ARGTYPE_STRING}, + {0, 0, 0, 0} }; static void diff --git a/gpsbabel/gpspilot.c b/gpsbabel/gpspilot.c index 267fea2b6..61362df27 100644 --- a/gpsbabel/gpspilot.c +++ b/gpsbabel/gpspilot.c @@ -54,8 +54,8 @@ static char *dbname = NULL; static arglist_t gpspilot_args[] = { - {"dbname", &dbname, "Database name"}, - {0, 0, 0} + {"dbname", &dbname, "Database name", ARGTYPE_STRING}, + {0, 0, 0, 0} }; static void diff --git a/gpsbabel/gpx.c b/gpsbabel/gpx.c index be421e994..9de09829b 100644 --- a/gpsbabel/gpx.c +++ b/gpsbabel/gpx.c @@ -63,6 +63,9 @@ static FILE *fd; static FILE *ofd; static void *mkshort_handle; +static const char *input_string = NULL; +static int input_string_len = 0; + static time_t file_time; static char *gsshortnames = NULL; @@ -733,9 +736,16 @@ gpx_cdata(void *dta, const XML_Char *s, int len) void gpx_rd_init(const char *fname, const char *args) { - fd = fopen(fname, "r"); - if (fd == NULL) { - fatal(MYNAME ": Cannot open %s for reading\n", fname ); + if ( fname[0] ) { + fd = fopen(fname, "r"); + if (fd == NULL) { + fatal(MYNAME ": Cannot open %s for reading\n", fname ); + } + } + else { + fd = NULL; + input_string = fname+1; + input_string_len = strlen(input_string); } if (get_option(args, "logpoint") != NULL) @@ -758,7 +768,9 @@ gpx_rd_deinit(void) if ( cdatastr ) { xfree(cdatastr); } - fclose(fd); + if (fd) { + fclose(fd); + } } void @@ -786,11 +798,25 @@ gpx_read(void) int len; int done = 0; char buf[MY_CBUF]; + int result = 0; while (!done) { - len = fread(buf, 1, sizeof(buf), fd); - done = feof(fd) || !len; - if (!XML_Parse(psr, buf, len, done)) { + if ( fd ) { + len = fread(buf, 1, sizeof(buf), fd); + done = feof(fd) || !len; + result = XML_Parse(psr, buf, len, done); + } + else if (input_string) { + done = 0; + result = XML_Parse(psr, input_string, + input_string_len, done ); + done = 1; + } + else { + done = 1; + result = -1; + } + if (!result) { fatal(MYNAME ": XML parse error at %d: %s\n", XML_GetCurrentLineNumber(psr), XML_ErrorString(XML_GetErrorCode(psr))); @@ -1131,10 +1157,13 @@ gpx_write(void) static arglist_t gpx_args[] = { - { "gsshortnames", &gsshortnames, "Prefer shorter descriptions from Groundspeak files"}, - { "snlen", &snlen, "Length of generated shortnames" }, - { "suppresswhite", &suppresswhite, "Suppress whitspace in generated shortnames" }, - { 0, 0, 0} + { "gsshortnames", &gsshortnames, + "Prefer shorter descriptions from Groundspeak files", + ARGTYPE_BOOL }, + { "snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + { "suppresswhite", &suppresswhite, + "Suppress whitespace in generated shortnames", ARGTYPE_BOOL }, + { 0, 0, 0, 0 } }; ff_vecs_t gpx_vecs = { diff --git a/gpsbabel/magproto.c b/gpsbabel/magproto.c index c23ea0167..90d66e07d 100644 --- a/gpsbabel/magproto.c +++ b/gpsbabel/magproto.c @@ -689,10 +689,11 @@ termwrite(char *obuf, int size) static arglist_t mag_args[] = { - {"baud", &bs, "Numeric value of bitrate (baud=4800)"}, - {"noack", &noack, "Suppress use of handshaking in name of speed"}, - {"deficon", &deficon, "Default icon name"}, - {0, 0, 0} + {"baud", &bs, "Numeric value of bitrate (baud=4800)", ARGTYPE_INT }, + {"noack", &noack, "Suppress use of handshaking in name of speed", + ARGTYPE_BOOL}, + {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, + {0, 0, 0, 0} }; static void diff --git a/gpsbabel/mapsource.c b/gpsbabel/mapsource.c index 553a86f97..26f2f1b7b 100644 --- a/gpsbabel/mapsource.c +++ b/gpsbabel/mapsource.c @@ -52,8 +52,8 @@ char *snlen; static arglist_t mps_args[] = { - {"snlen", &snlen, "Length of generated shortnames" }, - {0, 0, 0} + {"snlen", &snlen, "Length of generated shortnames", ARGTYPE_INT }, + {0, 0, 0, 0} }; const char * diff --git a/gpsbabel/pcx.c b/gpsbabel/pcx.c index 7faa6888c..5ba54d38f 100644 --- a/gpsbabel/pcx.c +++ b/gpsbabel/pcx.c @@ -32,8 +32,8 @@ static char *deficon = "Waypoint"; static arglist_t pcx_args[] = { - {"deficon", &deficon, "Default icon name"}, - {0, 0, 0} + {"deficon", &deficon, "Default icon name", ARGTYPE_STRING }, + {0, 0, 0, 0} }; static void diff --git a/gpsbabel/polygon.c b/gpsbabel/polygon.c index fbc7ae56c..4386cad18 100644 --- a/gpsbabel/polygon.c +++ b/gpsbabel/polygon.c @@ -49,9 +49,11 @@ typedef struct { static arglist_t polygon_args[] = { - {"file", &polyfileopt, "File containing vertices of polygon"}, - {"exclude", &exclopt, "Exclude points inside the polygon"}, - {0, 0, 0} + {"file", &polyfileopt, "File containing vertices of polygon", + ARGTYPE_FILE | ARGTYPE_REQUIRED }, + {"exclude", &exclopt, "Exclude points inside the polygon", + ARGTYPE_BOOL }, + {0, 0, 0, 0} }; static void polytest ( double lat1, double lon1, diff --git a/gpsbabel/position.c b/gpsbabel/position.c index 3b4967099..82a2d1288 100644 --- a/gpsbabel/position.c +++ b/gpsbabel/position.c @@ -42,17 +42,22 @@ typedef struct { static arglist_t position_args[] = { - {"distance", &distopt, "Maximum positional distance (required)"}, - {0, 0, 0} + {"distance", &distopt, "Maximum positional distance", + ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + {0, 0, 0, 0} }; static arglist_t radius_args[] = { - {"lat", &latopt, "Latitude for center point (D.DDDDD)"}, - {"lon", &lonopt, "Longitude for center point (D.DDDDD)"}, - {"distance", &distopt, "Maximum distance from center"}, - {"exclude", &exclopt, "Exclude points close to center"}, - {0, 0, 0} + {"lat", &latopt, "Latitude for center point (D.DDDDD)", + ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + {"lon", &lonopt, "Longitude for center point (D.DDDDD)", + ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + {"distance", &distopt, "Maximum distance from center", + ARGTYPE_FLOAT | ARGTYPE_REQUIRED }, + {"exclude", &exclopt, "Exclude points close to center", + ARGTYPE_BOOL }, + {0, 0, 0, 0} }; static double diff --git a/gpsbabel/quovadis.c b/gpsbabel/quovadis.c index ef2631b87..bcc226ae4 100644 --- a/gpsbabel/quovadis.c +++ b/gpsbabel/quovadis.c @@ -35,8 +35,8 @@ static char *dbname = NULL; static arglist_t quovadis_args[] = { - {"dbname", &dbname, "Database name"}, - {0, 0, 0} + {"dbname", &dbname, "Database name", ARGTYPE_STRING}, + {0, 0, 0, 0} }; static struct qv_icon_mapping mapping[] = { diff --git a/gpsbabel/tiger.c b/gpsbabel/tiger.c index bafedc465..4a97d4c08 100644 --- a/gpsbabel/tiger.c +++ b/gpsbabel/tiger.c @@ -48,13 +48,17 @@ static char *clickmap = NULL; static arglist_t tiger_args[] = { - {"nolabels", &nolabels, "Suppress labels on generated pins."}, - {"genurl", &genurl, "Generate file with lat/lon for centering map."}, - {"scale", &scale, "Dimension in pixels of map."}, + {"nolabels", &nolabels, "Suppress labels on generated pins.", + ARGTYPE_BOOL }, + {"genurl", &genurl, "Generate file with lat/lon for centering map.", + ARGTYPE_OUTFILE }, + {"scale", &scale, "Dimension in pixels of map.", + ARGTYPE_INT}, #if CLICKMAP - {"clickmap", &clickmap, "Generate Clickable map web page."}, + {"clickmap", &clickmap, "Generate Clickable map web page.", + ARGTYPE_BOOL}, #endif - {0, 0, 0} + {0, 0, 0, 0} }; diff --git a/gpsbabel/vecs.c b/gpsbabel/vecs.c index 2f2833901..3d7cd943b 100644 --- a/gpsbabel/vecs.c +++ b/gpsbabel/vecs.c @@ -339,8 +339,9 @@ disp_vecs(void) for (vec = vec_list; vec->vec; vec++) { printf(VEC_FMT, vec->name, vec->desc); for (ap = vec->vec->args; ap && ap->argstring; ap++) { - printf(" %-18.18s %-.50s\n", - ap->argstring, ap->helpstring); + printf(" %-18.18s %-.50s %s\n", + ap->argstring, ap->helpstring, + (ap->argtype & ARGTYPE_REQUIRED)?"(required)":""); } } diff --git a/gpsbabel/xcsv.c b/gpsbabel/xcsv.c index e3edbecc8..248ef58d8 100644 --- a/gpsbabel/xcsv.c +++ b/gpsbabel/xcsv.c @@ -40,14 +40,21 @@ char *xcsv_urlbase; static arglist_t xcsv_args[] = { - {"style", &styleopt, "Full path to XCSV style file (required)"}, - {"snlen", &snlenopt, "Max synthesized shortname length"}, - {"snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames"}, - {"snupper", &snupperopt, "(0/1) UPPERCASE synth. shortnames"}, - {"snunique", &snuniqueopt, "(0/1) Make synth. shortnames unique"}, - {"urlbase", &xcsv_urlbase, "Basename prepended to URL on output"}, - {"prefer_shortnames", &prefer_shortnames, "Use shortname instead of description"}, - {0, 0, 0} + {"style", &styleopt, "Full path to XCSV style file", + ARGTYPE_FILE | ARGTYPE_REQUIRED }, + {"snlen", &snlenopt, "Max synthesized shortname length", + ARGTYPE_INT}, + {"snwhite", &snwhiteopt, "(0/1) Allow whitespace synth. shortnames", + ARGTYPE_BOOL}, + {"snupper", &snupperopt, "(0/1) UPPERCASE synth. shortnames", + ARGTYPE_BOOL}, + {"snunique", &snuniqueopt, "(0/1) Make synth. shortnames unique", + ARGTYPE_BOOL}, + {"urlbase", &xcsv_urlbase, "Basename prepended to URL on output", + ARGTYPE_STRING}, + {"prefer_shortnames", &prefer_shortnames, + "Use shortname instead of description", ARGTYPE_BOOL }, + {0, 0, 0, 0} }; /* a table of config file constants mapped to chars */ -- 2.30.2